/**
 * 
 */
package jvs.peer.net;

import java.io.Serializable;
import java.net.SocketAddress;

/**
 * @author qiangli
 * 
 */
public class PeerAddress extends SocketAddress implements Serializable {

	private static final long serialVersionUID = 1L;

	private String realm = "xmpp";

	private String id = null;

	private String resource = null;

	private String nickname = null;
	
	private String ip = null;

	protected PeerAddress() {
	}

	public PeerAddress(String realm, String id) {
		this.realm = realm;
		this.id = id;
	}

	public PeerAddress(String realm, String id, String resource) {
		this.realm = realm;
		this.id = id;
		this.resource = resource;
	}

	public String getRealm() {
		return realm;
	}

	public void setRealm(String realm) {
		this.realm = realm;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getResource() {
		return resource;
	}

	public void setResource(String resource) {
		this.resource = resource;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((realm == null) ? 0 : realm.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PeerAddress other = (PeerAddress) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (realm == null) {
			if (other.realm != null)
				return false;
		} else if (!realm.equals(other.realm))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "PeerAddress [realm=" + realm + ", id=" + id + ", resource="
				+ resource + ", nickname=" + nickname + "]";
	}
}
